package cn.hchaojie.camp.day07;

import org.junit.Test;

public class DemoString {
	@Test
	public void testCreate() {
		String s1 = "abc";	// 创建字符串 		s1 是在常量池里面
		String s2 = new String("abc");			// s2 是在堆里面
		String s3 = "abc";
		String s4 = new String("abc");
		
		System.out.println(s1 == s3);	// 
		System.out.println(s1 == s2);	// false
		System.out.println(s2 == s4);	// false
		System.out.println(s2.equals(s4));	// true
		System.out.println(s1.equals(s2));
	}
	
	@Test
	public void testStringIterate() {
		String s1 = "hello world";
		for (int i = 0; i < s1.length(); i++) {
			System.out.print(s1.charAt(i));
		}
	}
	
	@Test
	public void array2String() {
		int[] array = {1, 2, 3, 4};
		
		String s = "";
		for (int element : array) {
			s = s + element;		// 字符串拼接
		}
		
		System.out.println(s);
	}
}
